package com.smart_campus.campus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.campus.vo.CampusCarouselVo;
import com.smart_campus.sys.common.DataGridView;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.campus.mapper.CampusCarouselMapper;
import com.smart_campus.campus.domain.CampusCarousel;
import com.smart_campus.campus.service.CampusCarouselService;

import java.util.List;

/**
 * @author Alfred
 * @time: 2020/6/24 8:43
 * 
 */
@Service
public class CampusCarouselServiceImpl implements CampusCarouselService{

    @Resource
    private CampusCarouselMapper campusCarouselMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.campus.service.impl.CampusCarouselServiceImpl",key = "#id")
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return campusCarouselMapper.deleteByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusCarouselServiceImpl",key = "#result.id")
    @Override
    public CampusCarousel insert(CampusCarousel record) {
        campusCarouselMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusCarouselServiceImpl",key = "#result.id")
    @Override
    public CampusCarousel insertSelective(CampusCarousel record) {
        campusCarouselMapper.insertSelective(record);
        return record;
    }
    
    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.campus.service.impl.CampusCarouselServiceImpl",key = "#id")
    @Override
    public CampusCarousel selectByPrimaryKey(Integer id) {
        return campusCarouselMapper.selectByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusCarouselServiceImpl",key = "#result.id")
    @Override
    public CampusCarousel updateByPrimaryKeySelective(CampusCarousel record) {
        campusCarouselMapper.updateByPrimaryKeySelective(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusCarouselServiceImpl",key = "#result.id")
    @Override
    public CampusCarousel updateByPrimaryKey(CampusCarousel record) {
        campusCarouselMapper.updateByPrimaryKey(record);
        return record;
    }
    
    @Override
    public DataGridView queryCarousel(CampusCarouselVo campusCarouselVo) {
        Page<Object> page= PageHelper.startPage(campusCarouselVo.getPage(),campusCarouselVo.getLimit());
        List<CampusCarouselVo> carousels = this.campusCarouselMapper.queryCarousel(campusCarouselVo);
        return new DataGridView(page.getTotal(),carousels);
    }

    @Override
    public int updateFilt(CampusCarousel carousel) {
        return campusCarouselMapper.updateFilt(carousel);
    }

}
